package edu.predatorwars.shared.models;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;


/**
 * Class that contains player IP and player name
 */
@JsonIgnoreProperties(ignoreUnknown=true)
public class PlayerConnectionInfo {
	
	private String name;
	private String ipAddress;

	@JsonCreator
	public PlayerConnectionInfo(@JsonProperty("name") String name, @JsonProperty("ipAddress") String ipAddress) {
		this.name = name;
		this.ipAddress = ipAddress;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	
	public String getName() {
		return name;
	}
	
	public String getIpAddress() {
		return ipAddress;
	}
	
	public String getResourceUrl() {
		return "http://" + ipAddress + "/predatorwars/client/message";
	}
	
	@Override public boolean equals(Object object) {
		if (!(object instanceof PlayerConnectionInfo)) {
			return false;
		}
		PlayerConnectionInfo info = (PlayerConnectionInfo)object;
		return name.equals(info.name) && ipAddress.equals(info.ipAddress);
	}
}
